package cn.wd.common.util;

import org.springframework.util.StringUtils;

/**
 * @author wangdong
 * @date 2024/9/14 15:31
 * @Description: 字符串工具类
 **/
public class StrUtils {

    public static boolean isNotEmpty(String str) {
        return str != null && !str.isEmpty();
    }

    public static boolean hasText(String str) {
        return StringUtils.hasText(str);
    }

    public static boolean isBlank(String str) {
        return str == null || str.trim().length() == 0;
    }

    public static String substring(String input, int start, int end) {
        if (input == null) {
            return null;
        }

        int len = input.length();
        if (start < 0) {
            start = len + start;
            if (start < 0) {
                start = 0;
            }
        } else if (start > len) {
            start = len;
        }

        if (end < 0) {
            end = len + end;
            if (end < 0) {
                end = len;
            }
        } else if (end > len) {
            end = len;
        }

        if (start > end) {
            return "";
        }

        return input.substring(start, end);
    }
}
